package edu.vital.energy.longevity.ch10.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import edu.vital.energy.longevity.ch10.domain.Article;
import edu.vital.energy.longevity.ch10.mapper.ArticleMapper;
import edu.vital.energy.longevity.ch10.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.*;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class ArticleServiceImpl implements ArticleService {
    @Autowired
    private ArticleMapper articleMapper;

    @Autowired
    private CacheManager cacheManager;

    @Override
    public List<Article> findAllArticles() {
        return articleMapper.selectList(null);
    }

    @Override
    public Article findArticleById(int id) {
        return articleMapper.selectById(id);
    }

    @Override
    public List<Article> insertArticle(Article article) {
        articleMapper.insert(article);
        return articleMapper.selectList(null);
    }

    @Override
    public List<Article> updateArticle(Article article) {
        articleMapper.updateById(article);
        return articleMapper.selectList(null);
    }

    @Override
    public List<Article> deleteArticle(int id) {
        articleMapper.deleteById(id);
        return articleMapper.selectList(null);
    }

    @Override
    public List<Article> searchArticles(String title, String author) {

        // 执行数据库查询

        
        List<Article> result = articleMapper.selectList(queryWrapper);
        

        
        return result;
    }
}